﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace Task244444
{
    class Program
    {
        static void Main(string[] args)
        {
            //定义数据库
            string connString = "server=.;database=Game;Integrated Security=true";
            //创建连接对象
            SqlConnection conn = new SqlConnection(connString);
            //打开数据库连接
            conn.Open();
            //检测数据库连接是否打开
            if (conn.State==ConnectionState.Open)
            {
                //创建插入的SQL语句(输出数据库中游戏的全部信息)
                string sql = "select ID,Name,Price,Stock,XiaoJi from games";
                //创建Command对象
                SqlCommand cmd = new SqlCommand(sql,conn);
                //执行SQL语句
                SqlDataReader reader = cmd.ExecuteReader();
                Console.WriteLine("序号\t游戏名称\t\t游戏价格\t\t库存数量\t小计");
                Console.WriteLine("*******************************************************************************************************");
                //使用循环，逐行读取数据
                while (reader.Read())
                {
                    Console.WriteLine("{0}\t{1}\t\t{2:C}元\t\t{3}\t{4:C}元",
                        reader["ID"],
                        reader["Name"],
                        reader["Price"],
                        reader["Stock"],
                        reader["XiaoJi"]
                        );
                }
                //关闭DataReade对象
                reader.Close();

            }
            //关闭数据库连接
            conn.Close();
        }
    }
}
